package gui.win.runassembly;

import core.para.Para;
import gui.VTL1;
import gui.processor.Processor;
import gui.processor.Worker;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Buttons extends JPanel implements ActionListener{
    private JButton close, process;
    private RunAssembly pipeline;
    private VTL1 segL1;
    public Buttons(RunAssembly barCodes, VTL1 segL1){
        super(new BorderLayout());
        this.pipeline = barCodes;
        this.segL1 = segL1;
        this.add(getButton(close = new JButton("CANCEL"), 212, 22, new Color(102, 102, 102), new Color(178, 178, 178), this, "CANCEL"), BorderLayout.WEST);
        this.add(getButton(process = new JButton("ASSEMBLE"), 212, 22, new Color(255, 0, 0), new Color(178, 178, 178), this, "ASSEMBLE"), BorderLayout.EAST);
    }
    
    public void actionPerformed(ActionEvent evt) {
        Object source = evt.getSource(); 
        if(source == close){pipeline.dispose();}
        else if(source == process){
            Para.PATH_TO_FOWARD_READS = pipeline.getPathToFwdReads();
            Para.PATH_TO_REVERSE_READS = pipeline.getPathToRevReads();
            Para.PATH_TO_OUTPUT =  pipeline.getPathToOutput();
            Para.PATH_TO_LOGFILE =  pipeline.getPathToLogFile();
            
            Processor processor = new Processor(segL1);
            processor.setTask(Processor.TASK_RUN_ASSEMBLY);
            Worker sl = new Worker(processor);
            sl.execute();
            pipeline.dispose();
        }
    }
    public void closeFrame(){pipeline.dispose();}
    
    public static JPanel getButton(JButton st, int width, int height, Color fCol, Color bCol, ActionListener al, String tooltip){
        st.setForeground(fCol);
        st.setBackground(bCol);
        st.setPreferredSize(new Dimension(width, height));
        st.addActionListener(al);
        st.setToolTipText(tooltip);
        JPanel p = new JPanel(new FlowLayout());
        p.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
        p.setOpaque(false);
        p.add(st);
        return p;
    }
}
